home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 626-637 / disk_632 / printfiles / source / prf_rexx.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  8KB  |  212 lines

  1. /* prf_rexx.c  */
  2. /* V1.1 10-9-92 */
  3.  
  4. #include "prf.h"
  5. #include <rexx/rexxio.h>
  6. #include <rexx/rxslib.h>
  7. #include <rexx/errors.h>
  8. #include <rexx/storage.h>
  9.  
  10. #pragma libcall RexxSysBase CreateArgString 7e 0802
  11. #pragma libcall RexxSysBase DeleteArgString 84 801
  12. #pragma libcall RexxSysBase LengthArgString 8a 801
  13. #pragma libcall RexxSysBase CreateRexxMsg   90 09803
  14. #pragma libcall RexxSysBase DeleteRexxMsg   96 801
  15.  
  16. UBYTE *CreateArgString(UBYTE *string,unsigned long length);
  17. void  DeleteArgString(UBYTE *argstring);
  18. ULONG LenghtArgString(UBYTE *argstring);
  19. struct RexxMsg *CreateRexxMsg(struct MsgPort *port, UBYTE *extension,UBYTE *host);
  20. void DeleteRexxMsg(struct RexxMsg *packet);
  21.  
  22. struct rexx_Cmd
  23.        {
  24.         UBYTE *rx_cmd;
  25.         ULONG  rx_code;
  26.        };
  27.  
  28. struct rexx_Cmd rexxCmd[] =
  29.        {
  30.         T_RX_RESET,CMD_RESETALL,
  31.         T_RX_CLEAR,CMD_CLEARLIST,
  32.         T_RX_OPENWINDOW,CMD_OPENWD,
  33.         T_RX_CLOSEWINDOW,CMD_CLOSEWD,
  34.         T_RX_INSFILE,CMD_STR_INSERT,
  35.         T_RX_REMFILE,CMD_REMOVE,
  36.         T_RX_PAGE,CMD_PAGE_ON,
  37.         T_RX_TIME,CMD_TIME_ON,
  38.         T_RX_FILE,CMD_NAME_ON,
  39.         T_RX_FF,CMD_FF_ON,
  40.         T_RX_CRLF,CMD_CRLF_ON,
  41.         T_RX_FOOT,CMD_FOOT,
  42.         T_RX_HEAD,CMD_HEAD,
  43.         T_RX_QUIT,CMD_RXQUIT,
  44.         T_RX_DATE,CMD_DATE_ON,
  45.         T_RX_LINE,CMD_LINE_ON,
  46.         T_RX_LINES,CMD_LINES,
  47.         T_RX_RMARGIN,CMD_RMARGIN,
  48.         T_RX_LMARGIN,CMD_LMARGIN,
  49.         T_RX_DRAFT,CMD_DRAFT,
  50.         T_RX_LQ,CMD_LQ,
  51.         T_RX_PITCH6,CMD_PITCH6,
  52.         T_RX_PITCH8,CMD_PITCH8,
  53.         T_RX_10CPI,CMD_10CPI,
  54.         T_RX_12CPI,CMD_12CPI,
  55.         T_RX_15CPI,CMD_15CPI,
  56.         T_RX_PRINT,CMD_PRINT,
  57.         T_RX_SAVEPREFS,CMD_SAVEPREFS,
  58.         T_RX_STATUS,CMD_STATUS,
  59.         T_RX_VERSION,CMD_VERSION,
  60.         NULL,0
  61.        };
  62.  
  63. char *RexxPortName   = RXPORTNAME;
  64.  
  65. void AttemptOpenRexx(struct prf_info *info)
  66. {
  67.  if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0L))
  68.  {
  69.   Forbid();
  70.   if(FindPort(RexxPortName))
  71.   {
  72.    Permit();
  73.   }
  74.   else
  75.   {
  76.    if(info->rexxPort = CreatePort(RexxPortName,0L))Permit();
  77.   }
  78.  }
  79. }
  80.  
  81. void CloseRexx(struct prf_info *info)
  82. {
  83.  if(info->rexxPort)
  84.  {
  85.   DeletePort(info->rexxPort);
  86.  }
  87.  if(RexxSysBase) CloseLibrary((struct Library *)RexxSysBase);
  88. }
  89.  
  90. long HandleRexxMsg(struct prf_info *info)
  91. {
  92.  UBYTE     filename[STR_SIZE];
  93.  long rc = CMD_NEUTRAL;
  94.  long numarg;
  95.  long i,found,c;
  96.  UBYTE cmd_string[STR_SIZE],arg1[STR_SIZE],arg2[STR_SIZE],arg3[STR_SIZE];
  97.  numarg  =  (long)sscanf(info->rmsg->rm_Args[0],"%s %s %s %s",cmd_string,arg1,arg2,arg3);
  98.  c = RX_CMD_NEUTRAL;
  99.  if(!strnicmp(arg1,T_RX_ON,strlen(arg1)))c = RX_CMD_ON;
  100.  found = FALSE;i = 0L;
  101.  while(!found)
  102.  {
  103.   if(rexxCmd[i].rx_cmd == NULL){found = TRUE; i = -1L;}
  104.   else
  105.   {
  106.    if(!strnicmp(rexxCmd[i].rx_cmd,cmd_string,strlen(cmd_string)))
  107.    {
  108.     found = TRUE;
  109.     i=rexxCmd[i].rx_code;
  110.    }
  111.    else i++;
  112.   }
  113.  }
  114.  if(i != -1L)
  115.  {
  116.   switch(i)
  117.   {
  118.    case CMD_STATUS      : if(info->rmsg->rm_Action & (1L << RXFB_RESULT))
  119.                           {
  120.                            if(info->flags & FLAG_PRINT)
  121.                             info->rmsg->rm_Result2 = (long)CreateArgString(T_RX_PMSG,strlen(T_RX_PMSG));
  122.                            else
  123.                             info->rmsg->rm_Result2 = (long)CreateArgString(T_RX_WMSG,strlen(T_RX_WMSG));
  124.                           }
  125.                           break;
  126.    case CMD_VERSION     : if(info->rmsg->rm_Action & (1L << RXFB_RESULT))
  127.                           {
  128.                            info->rmsg->rm_Result2 = (long)CreateArgString(RX_VERSION_STR,strlen(RX_VERSION_STR));
  129.                           }
  130.                           break;
  131.  
  132.    case CMD_SAVEPREFS   : strcpy(filename,arg1);
  133.                           if(*filename) SavePreferences(info,filename);
  134.                            else rc = CMD_SAVEPREFS;
  135.                           break;
  136.    case CMD_FOOT        : strcpy(info->Footline,info->rmsg->rm_Args[0]+1+strlen(T_RX_FOOT));
  137.                           if(info->Swd)GT_SetGadgetAttrs(info->SGadgets[GD_Footline],info->Swd,NULL,GTST_String,info->Footline,TAG_DONE);
  138.                           break;
  139.    case CMD_HEAD        : strcpy(info->Headline,info->rmsg->rm_Args[0]+1+strlen(T_RX_HEAD));
  140.                           if(info->Swd)GT_SetGadgetAttrs(info->SGadgets[GD_Headline],info->Swd,NULL,GTST_String,info->Headline,TAG_DONE);
  141.                           break;
  142.    case CMD_OPENWD      : if(!stricmp(arg1,T_RX_CONTROL))
  143.                           {
  144.                            if(*arg2)SwdTags[0].ti_Data = atol(arg2);
  145.                            if(*arg3)SwdTags[1].ti_Data = atol(arg3);
  146.                            if(SwdTags[0].ti_Data > (info->PubScr->Width  - SwdTags[2].ti_Data))
  147.                               SwdTags[0].ti_Data = info->PubScr->Width   - SwdTags[2].ti_Data;
  148.                            if(SwdTags[1].ti_Data > (info->PubScr->Height - SwdTags[3].ti_Data))
  149.                               SwdTags[1].ti_Data = info->PubScr->Height  - SwdTags[3].ti_Data;
  150.                            rc = CMD_OPENWD;
  151.                           }
  152.                           else
  153.                           if(!stricmp(arg1,T_RX_PREFS))
  154.                           {
  155.                            if(*arg2)PwdTags[0].ti_Data = atol(arg2);
  156.                            if(*arg3)PwdTags[1].ti_Data = atol(arg3);
  157.                            if(PwdTags[0].ti_Data > (info->PubScr->Width  - PwdTags[2].ti_Data))
  158.                               PwdTags[0].ti_Data = info->PubScr->Width   - PwdTags[2].ti_Data;
  159.                            if(PwdTags[1].ti_Data > (info->PubScr->Height - PwdTags[3].ti_Data))
  160.                               PwdTags[1].ti_Data = info->PubScr->Height  - PwdTags[3].ti_Data;
  161.                            rc = CMD_OPENPWD;
  162.                           }
  163.                           break;
  164.    case CMD_CLOSEWD     : if(!stricmp(arg1,T_RX_CONTROL)) rc = CMD_CLOSEWD;
  165.                            else if(!stricmp(arg1,T_RX_PREFS)) rc = CMD_CLOSEPWD;
  166.                           break;
  167.    case CMD_STR_INSERT  : if(*arg1)
  168.                           {
  169.                            long cmd = CMD_INSERTTAIL;
  170.                            info->Special1 = (APTR)arg1;
  171.                            info->Special2 = (APTR)&cmd;
  172.                            InsertName(info);
  173.                            info->Special1 = NULL;
  174.                            info->Special2 = NULL;
  175.                           }
  176.                           break;
  177.    case CMD_REMOVE      : info->Special1 = (APTR)arg1;
  178.                           RemoveName(info);
  179.                           info->Special1 = NULL;
  180.                           break;
  181.    case CMD_RMARGIN     : if(*arg1)info->Rmargin = atol(arg1);
  182.                           if(info->Pwd)GT_SetGadgetAttrs(info->PGadgets[GD_Rmargin - PGD],info->Pwd,NULL,GTIN_Number,info->Rmargin,TAG_DONE);
  183.                           break;
  184.    case CMD_LMARGIN     : if(*arg1)info->Lmargin = atol(arg1);
  185.                           if(info->Pwd)GT_SetGadgetAttrs(info->PGadgets[GD_Lmargin - PGD],info->Pwd,NULL,GTIN_Number,info->Lmargin,TAG_DONE);
  186.                           break;
  187.    case CMD_LINES       : if(*arg1)info->Lines = atol(arg1);
  188.                           if(info->Pwd)GT_SetGadgetAttrs(info->PGadgets[GD_Linesperpage - PGD],info->Pwd,NULL,GTIN_Number,info->Lines,TAG_DONE);
  189.                           break;
  190.    case CMD_PAGE_ON     : (c) ? (rc = CMD_PAGE_ON) : (rc = CMD_PAGE_OFF); break;
  191.    case CMD_LINE_ON     : (c) ? (rc = CMD_LINE_ON) : (rc = CMD_LINE_OFF); break;
  192.    case CMD_NAME_ON     : (c) ? (rc = CMD_NAME_ON) : (rc = CMD_NAME_OFF); break;
  193.    case CMD_TIME_ON     : (c) ? (rc = CMD_TIME_ON) : (rc = CMD_TIME_OFF); break;
  194.    case CMD_FF_ON       : (c) ? (rc = CMD_FF_ON)   : (rc = CMD_FF_OFF); break;
  195.    case CMD_CRLF_ON     : (c) ? (rc = CMD_CRLF_ON) : (rc = CMD_CRLF_OFF); break;
  196.    case CMD_DATE_ON     : (c) ? (rc = CMD_DATE_ON) : (rc = CMD_DATE_OFF); break;
  197.    default              : rc = i;
  198.                           break;
  199.   }
  200.  }
  201.  else
  202.  {
  203.   rc = CMD_NEUTRAL;
  204.   if(info->rmsg->rm_Action & (1L << RXFB_RESULT))
  205.   {
  206.    info->rmsg->rm_Result2 = (long)CreateArgString(T_RX_ERROR,strlen(T_RX_ERROR));
  207.    info->rmsg->rm_Result1 = RX_ERRORLEVEL;
  208.   }
  209.  }
  210.  return rc;
  211. }
  212.